package net.optix.ip.business
{
	import com.adobe.cairngorm.business.Responder;
	
	import mx.rpc.http.HTTPService;
	
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.ChangePasswordVO;
	import net.optix.ip.vo.ClientVO;
	import net.optix.ip.vo.CopyrightVO;
	import net.optix.ip.vo.InventorVO;
	import net.optix.ip.vo.PractitionerVO;
	import net.optix.ip.vo.RegisterVO;
	import net.optix.ip.vo.UserVO;
	
	public class UserDelegate
	{
		private var responder:Responder;
		private var service:HTTPService;
		
		public function	listener():void
		{
			service.method = "POST";
            service.resultFormat	=	HTTPService.RESULT_FORMAT_E4X;
            service.addEventListener("result", responder.onResult);
            service.addEventListener("fault", responder.onFault);
		}

		public function clientRegister(responder:Responder,vo:RegisterVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/ClientRegister";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	Business:vo.name,
            	Email:vo.email,
            	Password:vo.password
            });
		}
		
		public function practitionerRegister(responder:Responder,vo:RegisterVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/PractitionerRegister";
            this.listener();
            service.send({
            	Name:vo.name,
            	Email:vo.email,
            	Password:vo.password
            });
		}
		
		public function userLogin(responder:Responder,vo:UserVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/UserLogin";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	Email:vo.email,
            	Password:vo.password
            });
		}
		
		public function getUser(responder:Responder,userID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetUser";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	UserID:userID
            });
		}
		
		public function editPersonalInformation(responder:Responder,vo:UserVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/EditPersonalInformation";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	UserID:vo.userID,
            	FirstName:vo.firstName,
            	LastName:vo.lastName,
            	Address:vo.address,
            	City:vo.city,
            	State:vo.state,
            	PostalCode:vo.postalCode,
            	Country:vo.country,
            	WorkPhone:vo.workPhone,
            	HomePhone:vo.homePhone,
            	CellPhone:vo.cellPhone,
            	Fax:vo.fax
            });
		}
		
		public function changePassword(responder:Responder,vo:ChangePasswordVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/ChangePassword";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            service.send({
            	UserID:vo.userID,
            	OldPassword:vo.oldPassword,
            	NewPassword:vo.newPassword
            });
		}
		
		public function editBilling(responder:Responder,vo:ClientVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/EditBilling";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            service.send({
            	ClientID:vo.clientID,
            	Business:vo.business,
				BillingAddress:vo.billingAddress,
				BillingCity:vo.billingCity,
				BillingState:vo.billingState,
				BillingCountry:vo.billingCountry,
				BillingPostalCode:vo.billingPostalCode,
				TaxID:vo.taxID,
				Description:vo.description
			});
		}
		
		public function addInventor(responder:Responder,vo:InventorVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/AddInventor";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            service.send({
            	ClientID:vo.clientID,
            	FirstName:vo.firstName,
				LastName:vo.lastName,
				Email:vo.email,
				Message:vo.message
			});
		}
		
		public function addClient(responder:Responder,vo:ClientVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/AddClient";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
            service.send({Business:vo.business,
				Email:vo.email,
				Message:vo.message,
				FirstName:vo.firstName,
				LastName:vo.lastName});
		}
		
		public function addPractitioner(responder:Responder,vo:PractitionerVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/AddPractitioner";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		FirmID:vo.firmID,
           		FirstName:vo.firstName , 
				LastName:vo.lastName , 
				Email:vo.email,
				Message:vo.message, 
				BAttorney:vo.bAttorney == true ? 1:0,
				PatentBar:vo.bPatentBar == true ? 1:0,
				Editor:vo.bEditor == true ? 1:0,
				Draftsman:vo.bDraftsMan == true ? 1:0});
		}
		
		public function getPractitioners(responder:Responder,firmID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetPractitioners";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		FirmID:firmID
           		});
		}
		
		public function updatePractitioner(responder:Responder,vo:PractitionerVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/UpdatePractitioner";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		PractitionerID:vo.practitionerID,
				BAttorney: vo.bAttorney?1:0 , 
				BAgent: vo.bAgent?1:0 , 
				PatentBar : vo.bPatentBar?1:0 ,
				Editor: vo.bEditor?1:0,
				Draftsman: vo.bDraftsMan?1:0});
		}
		
		public function deletePractitioner(responder:Responder,practitionerID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/DeletePractitioner";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		PractitionerID:practitionerID
				 });
		}
		
		public function getPractitioner(responder:Responder,practitionerID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetPractitioner";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		PractitionerID:practitionerID
				 });
		}
		
		public function getInventors(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetInventors";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:clientID
           		});
		}
		
		public function updateInventor(responder:Responder,vo:InventorVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/UpdateInventor";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	
		}
		
		public function deleteInventor(responder:Responder,inventorID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/DeleteInventor";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		InventorID:inventorID
				 });
		}
		
		public function getInventor(responder:Responder,inventorID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetInventor";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		InventorID:inventorID
				 });
		}
		
		public function getClients(responder:Responder):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetClients";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		
           		});
		}
		
		public function updateClient(responder:Responder,vo:ClientVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/UpdateClient";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            service.send({
           		ClientID:vo.clientID
           		});
           	
		}
		
		public function deleteClient(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/DeleteClient";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:clientID
				 });
		}
		
		public function getClient(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetClient";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:clientID
				 });
		}
		
		public function getFirms(responder:Responder):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetFirms";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		
           		});
		}
		
		public function getFirmsWork(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetFirmsWork";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:clientID
           		});
		}
		
		public function updateFirms(responder:Responder,firms:String,type:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/UpdateFirms";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            service.send({
				Firms:firms,
				Type:type});
           	
		}
		
		public function deleteFirm(responder:Responder,firmID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/DeleteFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		FirmID:firmID
				 });
		}
		
		public function getFirm(responder:Responder,firmID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		FirmID:firmID
				 });
		}
		
		public function getCopyRight(responder:Responder,clientID:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/GetCopyRight";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:clientID
				 });
		}
		
		public function setCopyRight(responder:Responder,vo:CopyrightVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/User/SetCopyRight";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;    
            
           	service.send({
           		ClientID:vo.clientID,
           		Title:vo.title,
           		Created:vo.created,
           		Registered:vo.registered,
           		Registration:vo.registration,
           		IssuedTo:vo.issuedTo,
           		Type:vo.type,
           		Death:vo.death
				 });
		}
	}
}